/***************************************************************************
 *   Copyright (C) 2007 by Gaetano Mendola  *
 *   mendola@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include <iostream>

#include "combatlog.h"
#include "weapon.h"
#include "timer.h"

#include "events/eventdispatcher.h"
#include "events/buff.h"
#include "events/swing.h"

CombatLog::CombatLog()
{
    Events::EventDispatcher::instance().subscribe(Events::Event::TICK,      this);
    Events::EventDispatcher::instance().subscribe(Events::Event::SWING,     this);
    Events::EventDispatcher::instance().subscribe(Events::Event::CRITMELEE, this);
    Events::EventDispatcher::instance().subscribe(Events::Event::WF,        this);
    Events::EventDispatcher::instance().subscribe(Events::Event::BUFF,      this);
}


CombatLog::~CombatLog()
{
}


void CombatLog::notify(const Events::Event* anEvent)
{
    Events::Event::TYPE myType = anEvent->type();

    if ( myType ==  Events::Event::TICK ) {
        // std::cout << Timer::instance().tick()/1000.0 << std::endl;
    } else if ( myType == Events::Event::SWING ) {
        const Events::Swing *myEvent = dynamic_cast<const Events::Swing *>(anEvent);

        std::cout << Timer::instance().tick()/1000.0 << " SWING (" << myEvent->weapon().name() << ") - " << myEvent->weapon().speed() << std::endl;
    } else if ( myType == Events::Event::CRITMELEE ) {
        std::cout << Timer::instance().tick()/1000.0 << " CRITMELEE" << std::endl;
    } else if ( myType == Events::Event::BUFF ) {
        const Events::Buff* myEvent = dynamic_cast<const Events::Buff*>(anEvent);

        if (myEvent->action() == Events::Buff::GAIN ) {
            std::cout << Timer::instance().tick()/1000.0 << " BUFF GAINED: " << myEvent->buff()->name() << std::endl;
        } else if (myEvent->action() == Events::Buff::REFRESH ) {
            std::cout << Timer::instance().tick()/1000.0 << " BUFF REFRESH: " << myEvent->buff()->name() << std::endl;
        } else {
            std::cout << Timer::instance().tick()/1000.0 << " BUFF LOST: " << myEvent->buff()->name() << std::endl;
        }
    } else if ( myType ==  Events::Event::WF ) {
        std::cout << Timer::instance().tick()/1000.0 << " WF" << std::endl;
    }
}


